package net.kosev.battleships;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Configuration tool
 * 
 * @author Nikola
 *
 */
public class Config {
	
	/**
	 * Preferences file name
	 */
	public static final String PREFS_NAME = "BattleshipsPreferences";
	
	/**
	 * Is sound enabled
	 */
	public static boolean enabledSound = true;
	
	/**
	 * Is vibration enabled
	 */
	public static boolean enabledVibration = false;
	
	/**
	 * Is revealing destroyed ships enabled
	 */
	public static boolean enabledRevealing = true;
	
	/**
	 * Computer difficulty
	 */
	public static int computerDifficulty = 0;
	
	/**
	 * Save preferences
	 * 
	 * @param context	Activity context
	 */
	public static void save(Context context) {
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		
		editor.putBoolean("sound", enabledSound);
		editor.putBoolean("vibrate", enabledVibration);
		editor.putBoolean("reveal", enabledRevealing);
		editor.putInt("difficulty", computerDifficulty);
		
		editor.commit();
	}
	
	/**
	 * Load preferences
	 * 
	 * @param context	Activity context
	 */
	public static void load(Context context) {
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		
		enabledSound = settings.getBoolean("sound", true);
		enabledVibration = settings.getBoolean("vibrate", false);
		enabledRevealing = settings.getBoolean("reveal", true);
		computerDifficulty = settings.getInt("difficulty", 0);
	}
}
